package zzz.tuan2d.toidihoilo;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * CategoryAdapter
 * 
 * @author TUAN2D
 */
public class ListReportAdapter extends BaseAdapter {
	private LayoutInflater mLayoutInflater;
	private ArrayList<ReportModel> mListReport;

	public ListReportAdapter(Context context, ArrayList<ReportModel> mListReport) {
		this.mListReport = mListReport;
		mLayoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return mListReport.size();
	}

	@Override
	public Object getItem(int position) {
		return 0;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolderCategoryItem viewHolder;
		if (convertView == null) {
			// initial for the first time of this row
			convertView = mLayoutInflater.inflate(R.layout.item_report, null);
			viewHolder = new ViewHolderCategoryItem();
			viewHolder.textViewReportTitle = (TextView) convertView
					.findViewById(R.id.textViewReportTitle);
			viewHolder.textViewReportTime = (TextView) convertView
					.findViewById(R.id.textViewReportTime);
			viewHolder.textViewReportAuthor = (TextView) convertView
					.findViewById(R.id.textViewReportAuthor);
			viewHolder.textViewReportLocation = (TextView) convertView
					.findViewById(R.id.textViewReportLocation);
			convertView.setTag(viewHolder);
		} else {
			// initial for not the first time of this row
			viewHolder = (ViewHolderCategoryItem) convertView.getTag();
		}

		viewHolder.textViewReportTitle.setText(mListReport.get(position).title);
		viewHolder.textViewReportTime.setText(""
				+ mListReport.get(position).time);
		viewHolder.textViewReportAuthor
				.setText(mListReport.get(position).author);
		viewHolder.textViewReportLocation.setText(""
				+ mListReport.get(position).location);
		return convertView;
	}

	/**
	 * ViewHolderCategoryItem
	 * 
	 * @author TUAN2D : this class will contains all of the screen's fields
	 */
	private static class ViewHolderCategoryItem {
		private TextView textViewReportTitle, textViewReportTime,
				textViewReportAuthor, textViewReportLocation;
	}
}
